package com.yhy;

import java.util.HashMap;
import java.util.Map;

/**
 * describe:
 *
 * @author helloworldyu
 * @data 2017/11/16
 */
public class BasicElement{
	protected int hashCode=0;

	protected final Map<String, Object> properties = new HashMap<>();
	protected final int id;

	public BasicElement(int id)
	{
		this.id = id;
		this.hashCode=31*id;
	}


	public int getId() {
		return id;
	}

	public void setAttribute(String key, Object value) {
		properties.put(key, value);
	}


	public Object getAttribute(String key) {
		return properties.get(key);
	}


	public Object removeAttribute(String key) {
		return properties.remove(key);
	}


	public void clearAttributes() {
		properties.clear();
	}


	@Override
	public String toString() {
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.append("BasicElement{ id=").append(id)
				.append(", properties={" );

		for( Map.Entry<String, Object> entry : properties.entrySet() ){
			stringBuilder.append("key:").append(entry.getKey())
					.append("value:").append(entry.getValue()).append('\n');
		}
		stringBuilder.append("}" +
				"}");

		return stringBuilder.toString();
	}

}